from PIL import Image
from selenium import webdriver
import time;  # 引入time模块
def webscreen(i):
    print(i)
    if i == 1 or i == 700:
        print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    # url = 'http://192.168.20.58/gfwd/comments-1.html'
    url = `https://es-ipgwfgb4.kibana.tencentelasticsearch.com:5601/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-2M,to:now))&_a=(columns:!(),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'447a1ab0-a38a-11ec-88a0-85c98618490a',key:message,negate:!f,params:(query:%E6%9D%8E%E9%BE%99%E5%8D%8E),type:phrase),query:(match_phrase:(message:%E6%9D%8E%E9%BE%99%E5%8D%8E))),('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'447a1ab0-a38a-11ec-88a0-85c98618490a',key:message,negate:!f,params:(query:%E4%B8%8B%E5%8D%95%E6%8E%A5%E5%8F%A3%E5%85%A5%E5%8F%82),type:phrase),query:(match_phrase:(message:%E4%B8%8B%E5%8D%95%E6%8E%A5%E5%8F%A3%E5%85%A5%E5%8F%82)))),hideChart:!t,index:'447a1ab0-a38a-11ec-88a0-85c98618490a',interval:auto,query:(language:kuery,query:''),sort:!(!('@timestamp',desc)))`
    # driver = webdriver.Chrome("C:/Users/maimai/Downloads/chromedriver_win32/chromedriver.exe")
    # driver = webdriver.PhantomJS("‪D:/迅雷下载/phantomjs-2.1.1-windows/bin/phantomjs.exe")
    driver = webdriver.PhantomJS(r"D:\soft\phantomjs-2.1.1-windows\bin\phantomjs.exe")
    # ‪D:\迅雷下载\phantomjs-2.1.1-windows\bin\phantomjs.exe
    driver.set_page_load_timeout(300)
    driver.set_window_size(1280, 800)
    driver.get(url)

    imgelement = driver.find_element_by_id('testSpacing')
    location = imgelement.location
    size = imgelement.size
    savepath = r'./images/codingpy_' + str(i) + '.png'
    driver.save_screenshot(savepath)
    im = Image.open(savepath)
    left = location['x']
    top = location['y']
    right = left + size['width']
    bottom = location['y'] + size['height']
    im = im.crop((left, top, right, bottom))
    im.save(savepath)

